



#include "main.h"

#define	EEPROM_SCEND_ADDR  		0x0100
#define	EEPROM_DTCFLG_ADDR  	0x0200

#define	EEPROM_OBDDATA_ADDR  	0x0000	/*OBD内容的存储首地址*/
#define	EEPROM_DTCDATA_ADDR  	0x0300	/*DTC内容的存储首地址  - 尾地址 0x1B80*/

#define	EEPROM_Addr			0xA0			/*EEPROM写地址 读地址为 EEPROM_Addr|0x01*/
#define	EEPROM_RAddr		0xA1
#define EEPROM_W_CMD		0x03			/*写数据是帧头长度为3 单位u16*/
#define EEPROM_R_CMD		0x04			/*写数据是帧头长度为3 单位u16*/

#define 	EEPROM_RUN			0
#define 	EEPROM_NOMAL		1
#define 	EE_CRC16_ERR		2

#define 	EEPROM_PAGE			0x40




#define STOP		0
#define	IDEL		0
#define	RUN			1
#define	FINISH		2


typedef struct
{
	u16 	DV_Addr;			/*器件地址*/
	u16 	REG_TAddrH;			/*写REG-H地址*/
	u16 	REG_TAddrL;			/*写REG-L地址*/
	u16		P_Tx_DataArr[11];	/*发送的数据数组指针地址*/
	u8		Data_Lenth;			/*数据长度 发送长度为上方总长度*/
}ECU_EE_TX_STR;

ECU_EE_TX_STR	EE_TxStr;


typedef struct
{
	u16 	DV_Addr;			/*器件地址*/
	u16 	REG_TAddrH;			/*写REG-H地址*/
	u16 	REG_TAddrL;			/*写REG-L地址*/
	u16 	DV_RAddr;			/*读器件地址*/
	u16		P_Tx_DataArr[11];	/*发送的数据数组指针地址*/
	u8		Data_Lenth;			/*数据长度 发送长度为上方总长度*/
	u16		P_Rx_DataArr[11];	/*接收的数据数组指针地址*/

}ECU_EE_RX_STR;


ECU_EE_RX_STR	EE_RxStr;


u16 G_u16_EE_REG_RAdd = 0;
u16 G_u16_EE_REG_WAdd = 0;

u8 G_u8_EE_Data_Lenth = 0;
u8 G_u8_EE_DataCont = 0;

u32 G_u32_Data_WAdd = 0;
u32 G_u32_Data_RAdd = 0;


u8 G_u8_Dtc_WFlg = IDEL;
u8 G_u8_Dtc_RFlg = IDEL;


u8 ECU_EEPROM_DataPage(u32 u32_Data)
{
	u8 u8_Data = 0;
	u8_Data = EEPROM_PAGE - (u32_Data - (u32_Data/EEPROM_PAGE) * EEPROM_PAGE);
	return u8_Data;
}

 u16 ECU_EEPROM_AddDeal(u32 EE_Data_Addr,u8 Data_Lenth,u16 u16_Err_Num)
{
	u16 u16_Div_Data = 0;
	u16 u16_Rdl_Data = 0;

	u16 u16_Reg_RAdd = 0;

	if(Data_Lenth <= EEPROM_PAGE)
	{
		u16_Div_Data = u16_Err_Num/(EEPROM_PAGE/Data_Lenth);
		u16_Rdl_Data = u16_Err_Num%(EEPROM_PAGE/Data_Lenth);
		u16_Reg_RAdd = EE_Data_Addr + u16_Div_Data * EEPROM_PAGE + u16_Rdl_Data*Data_Lenth;
	}
	else
	{
		u16_Div_Data = (Data_Lenth / 60 + 1) * u16_Err_Num;
		u16_Reg_RAdd = EE_Data_Addr + u16_Div_Data * EEPROM_PAGE;
	}
	return u16_Reg_RAdd;
}

void ECU_EEPROM_RX_Tcomd(u8 u8_Lenth)
{
	u8 u8_i = 0;
	for(u8_i = 0;u8_i < u8_Lenth;u8_i++)
	{
		EE_RxStr.P_Tx_DataArr[u8_i] = IIC_Reve(0x00);
	}
	EE_RxStr.P_Tx_DataArr[u8_i] = IIC_Stop(0x00);
}

inline void ECU_EEPROM_RX_TBuff_Init(void)
{
	u8 u8_i = 0;
	for(u8_i = 0;u8_i < 10;u8_i++)
	{
		EE_RxStr.P_Tx_DataArr[u8_i] = IIC_Reve(0x00);
	}
	EE_RxStr.P_Tx_DataArr[u8_i] = IIC_Stop(0x00);
}

/********************************************************
**函数名：	ECU_EEPROM_PORT_INIT
**功能：	EEPROM模块初始化
**输入：	无
**输出：	无
**注意：	根据实际硬件电路确认通道
*********************************************************/
void ECU_EEPROM_PORT_INIT(void)
{
	BSW_GPIO_MUX_CONFIG(Bsw_Port_E,0,PORT_MUX_AS_GPIO);
	BSW_GPIO_Direction(PTE,0,1);
	BSW_GPIO_SetBits(PTE,0);

	ECU_EEPROM_RX_TBuff_Init();
}


u8 ECU_EEPROM_CRC16_Check(u16* P_u16_Data)
{
	u8 u8_Status = false;
	u16 u16_Crc16Num = 0;
	u16_Crc16Num = P_u16_Data[9];
	u16_Crc16Num =(u16_Crc16Num<<8) + P_u16_Data[10];
	if(u16_Crc16Num == ECU_CRC_EEPROM(P_u16_Data+1,8))
	{
		u8_Status = true;
	}
	return u8_Status;
}

/************读取数据************/
void ECU_EEPROM_READ_DATA(u16 REG_Add,u8 u8_Lenth)
{
	BSW_GPIO_SetBits(PTE,0);
	EE_RxStr.DV_Addr = IIC_Start(EEPROM_Addr);
	EE_RxStr.REG_TAddrH = IIC_Send((u8)(REG_Add>>8));
	EE_RxStr.REG_TAddrL = IIC_Send((u8)REG_Add);
	EE_RxStr.DV_RAddr = IIC_Start(EEPROM_RAddr);
	EE_RxStr.Data_Lenth = u8_Lenth + 5;
	ECU_EEPROM_RX_Tcomd(u8_Lenth);
	ECU_IIC_DMA_RDATA((u32)(&(EE_RxStr.DV_Addr)),(u32)(&(EE_RxStr.P_Rx_DataArr)),EE_RxStr.Data_Lenth);
}
/************写入数据************/
void ECU_EEPROM_WRIT_DATA(u16 REG_Add,u8 u8_Lenth)
{
	BSW_GPIO_ResetBits(PTE,0);
	EE_TxStr.DV_Addr = IIC_Start(EEPROM_Addr);
	EE_TxStr.REG_TAddrH = IIC_Send((u8)(REG_Add>>8));
	EE_TxStr.REG_TAddrL = IIC_Send((u8)REG_Add);
	EE_TxStr.Data_Lenth = u8_Lenth + 4;
	ECU_IIC_DMA_WDATA((u32)(&(EE_TxStr.DV_Addr)),EE_TxStr.Data_Lenth);
}


void ECU_Deal_WData(u8* P_u8_Data,u8 u8_Lenth)
{
	u8 u8_Count = 0;
	for(u8_Count = 0;u8_Count < u8_Lenth;u8_Count++)
	{
		EE_TxStr.P_Tx_DataArr[u8_Count]=	((*(P_u8_Data + u8_Count)) & 0xFF);
	}
	EE_TxStr.P_Tx_DataArr[u8_Lenth]=	IIC_Stop(0x00);
}

u8 ECU_EE_Run_WData(void)
{
	u8 u8_Status = false;
	u8 u8_W_Flg = RUN;
	u8 u8_W_Lenth  = 0;
	static u8 S_u8_EEW_Cnt = 0;
	if(S_u8_EEW_Cnt < 3)		/*配合外部的MC33771调用延时 使用达到每5ms调用一次*/
	{
		S_u8_EEW_Cnt ++;
	}
	else
	{
		S_u8_EEW_Cnt = 0;
		if(G_u8_EE_DataCont < G_u8_EE_Data_Lenth)
		{
			/************判断存储的数据长度是否大于10************/
			if((G_u8_EE_Data_Lenth - G_u8_EE_DataCont) > 10)
			{
				u8_W_Lenth = 10;
			}
			else
			{
				u8_W_Lenth = G_u8_EE_Data_Lenth - G_u8_EE_DataCont;
			}
			if(ECU_EEPROM_DataPage(G_u16_EE_REG_WAdd) <= u8_W_Lenth)/*判定是否需要翻页存储*/
			{
				u8_W_Flg = STOP;
				BSW_GPIO_SetBits(PTE,0);
				G_u16_EE_REG_WAdd = (G_u16_EE_REG_WAdd/EEPROM_PAGE)*EEPROM_PAGE + EEPROM_PAGE;
			}
			if(u8_W_Flg == RUN)
			{
				ECU_Deal_WData((u8*)G_u32_Data_WAdd,u8_W_Lenth);
				ECU_EEPROM_WRIT_DATA(G_u16_EE_REG_WAdd,u8_W_Lenth);
				G_u32_Data_WAdd = G_u32_Data_WAdd + u8_W_Lenth;
				G_u16_EE_REG_WAdd = G_u16_EE_REG_WAdd + u8_W_Lenth;
				G_u8_EE_DataCont = G_u8_EE_DataCont + u8_W_Lenth;
			}
		}
		else
		{
			/*最后一帧数据，置位完成标志*/
			G_u8_Dtc_WFlg = FINISH;
			u8_Status = true;
		}
	}
	return u8_Status;
}

void ECU_Deal_RData(u8* P_u8_Data,u8 u8_Lenth)
{
	u8 u8_Count = 0;
	for(u8_Count = 0;u8_Count < u8_Lenth;u8_Count++)
	{
		*(P_u8_Data + u8_Count) = EE_RxStr.P_Rx_DataArr[u8_Count+1] & 0xFF;
	}
}

u8 ECU_EE_Run_RData(void)
{
	u8 u8_Status = false;
	u8 u8_R_Flg = RUN;
	u8 u8_R_Lenth = 0;
	static u8 S_u8_R_Lenth  = 0;

	if(G_u8_EE_DataCont < G_u8_EE_Data_Lenth)
	{
		/************判断存储的数据长度是否大于10************/
		if((G_u8_EE_Data_Lenth - G_u8_EE_DataCont) > 10)
		{
			u8_R_Lenth = 10;
		}
		else
		{
			u8_R_Lenth = G_u8_EE_Data_Lenth - G_u8_EE_DataCont;
		}
		if(ECU_EEPROM_DataPage(G_u16_EE_REG_RAdd) <= u8_R_Lenth)/*判定是否需要翻页存储*/
		{
			u8_R_Flg = STOP;
			BSW_GPIO_SetBits(PTE,0);
			G_u16_EE_REG_RAdd = (G_u16_EE_REG_RAdd/EEPROM_PAGE)*EEPROM_PAGE + EEPROM_PAGE;
		}
		if(u8_R_Flg == RUN)
		{
			if(G_u8_EE_DataCont != 0)
			{
				ECU_Deal_RData((u8*)G_u32_Data_RAdd - S_u8_R_Lenth,S_u8_R_Lenth);
			}
			S_u8_R_Lenth = u8_R_Lenth;
			ECU_EEPROM_READ_DATA(G_u16_EE_REG_RAdd,u8_R_Lenth);
			G_u32_Data_RAdd = G_u32_Data_RAdd + u8_R_Lenth;
			G_u16_EE_REG_RAdd = G_u16_EE_REG_RAdd + u8_R_Lenth;
			G_u8_EE_DataCont = G_u8_EE_DataCont + u8_R_Lenth;
		}
	}
	else
	{
		ECU_Deal_RData((u8*)G_u32_Data_RAdd-S_u8_R_Lenth,S_u8_R_Lenth);
		/*最后一帧数据，置位完成标志*/
		G_u8_Dtc_RFlg = FINISH;
		u8_Status = true;
		S_u8_R_Lenth = 0;
	}
	return u8_Status;
}

 void ECU_EEPROM_PRT(void)
 {
	 BSW_GPIO_SetBits(PTE,0);
 }

 /********************************************************
 **函数名：	ECU_EE_WR_DTC_DATA
 **功能：		存储DTC指定的快照信息
 **输入参数：	Data_Addr 存储的数据数组指针
 **			Data_Lenth 快照信息长度
 **			u16_Err_Num 故障编号
 **返回值：	无
 **注意：		快照信息存储在固定的函数指针 异步存储注意读取当前是否空闲
 *********************************************************/
 void ECU_EE_WR_DTC_DATA(u32 Data_Addr,u8 Data_Lenth,u16 u16_Err_Num)
 {
 	/*初始化传递参数*/
 	G_u32_Data_WAdd = Data_Addr + u16_Err_Num*Data_Lenth;
 	G_u16_EE_REG_WAdd = ECU_EEPROM_AddDeal(EEPROM_DTCDATA_ADDR,Data_Lenth,u16_Err_Num);
 	G_u8_EE_Data_Lenth = Data_Lenth;
 	G_u8_EE_DataCont = 0;
 	ECU_EEPROM_DTC_WCMD();
 }
 /********************************************************
 **函数名：	ECU_EE_WR_DTC_DATA
 **功能：		读取DTC指定的快照信息
 **输入参数：	Data_Addr 存储的数据数组指针
 **			Data_Lenth 快照信息长度
 **			u16_Err_Num 故障编号
 **返回值：	无
 **注意：		快照信息存储在固定的函数指针 异步存储注意读取当前是否空闲
 *********************************************************/
 void ECU_EE_RR_DTC_DATA(u32 Data_Addr,u8 Data_Lenth,u16 u16_Err_Num)
 {
 	/*初始化传递参数*/
 	G_u32_Data_RAdd = Data_Addr + u16_Err_Num*Data_Lenth;
 	G_u16_EE_REG_RAdd = ECU_EEPROM_AddDeal(EEPROM_DTCDATA_ADDR,Data_Lenth,u16_Err_Num);
 	G_u8_EE_Data_Lenth = Data_Lenth;
 	G_u8_EE_DataCont = 0;
 	ECU_EEPROM_DTC_RCMD();
 }
 /********************************************************
 **函数名：	ECU_EE_WR_OBD_DATA
 **功能：		存储OBD指定的快照信息
 **输入参数：	Data_Addr 存储的数据数组指针
 **			Data_Lenth 快照信息长度
 **			u16_Err_Num 故障编号
 **返回值：	无
 **注意：		快照信息存储在固定的函数指针 异步存储注意读取当前是否空闲
 *********************************************************/
void ECU_EE_WR_OBD_DATA(u32 Data_Addr,u8 Data_Lenth,u16 u16_Err_Num)
{
	/*初始化传递参数*/
	G_u32_Data_WAdd = Data_Addr + u16_Err_Num*Data_Lenth;
	G_u16_EE_REG_WAdd = ECU_EEPROM_AddDeal(EEPROM_OBDDATA_ADDR,Data_Lenth,u16_Err_Num);
	G_u8_EE_Data_Lenth = Data_Lenth;
	G_u8_EE_DataCont = 0;
	ECU_EEPROM_OBD_WCMD();
}
/********************************************************
**函数名：	ECU_EE_RR_OBD_DATA
**功能：		读取OBD指定的快照信息
**输入参数：	Data_Addr 存储的数据数组指针
**			Data_Lenth 快照信息长度
**			u16_Err_Num 故障编号
**返回值：	无
**注意：		快照信息存储在固定的函数指针 异步存储注意读取当前是否空闲
*********************************************************/
void ECU_EE_RR_OBD_DATA(u32 Data_Addr,u8 Data_Lenth,u16 u16_Err_Num)
{
	/*初始化传递参数*/
	G_u32_Data_RAdd = Data_Addr + u16_Err_Num*Data_Lenth;
	G_u16_EE_REG_RAdd = ECU_EEPROM_AddDeal(EEPROM_OBDDATA_ADDR,Data_Lenth,u16_Err_Num);
	G_u8_EE_Data_Lenth = Data_Lenth;
	G_u8_EE_DataCont = 0;
	ECU_EEPROM_OBD_RCMD();
}







#define EE_IDEL				0
#define EE_OBD_Cmd_W		(1<<0)
#define EE_OBD_Cmd_R		(1<<1)
#define EE_DTC_Cmd_W		(1<<2)
#define EE_DTC_Cmd_R		(1<<3)
#define EE_UDS_Cmd_W		(1<<4)
#define EE_UDS_Cmd_R		(1<<5)

u8 G_u8_EE_CMD_NUM = 0;
u8 G_u8_EE_RUN_CmdNum = 0;
u8 G_u8_EE_RUN_CMD = 0;
u8 G_u8_EE_RUN_FLG = 0;

void ECU_EEPROM_OBD_WCMD(void)
{
	G_u8_EE_CMD_NUM |= EE_OBD_Cmd_W;
}
void ECU_EEPROM_OBD_RCMD(void)
{
	G_u8_EE_CMD_NUM |= EE_OBD_Cmd_R;
}
void ECU_EEPROM_DTC_WCMD(void)
{
	G_u8_EE_CMD_NUM |= EE_DTC_Cmd_W;
}
void ECU_EEPROM_DTC_RCMD(void)
{
	G_u8_EE_CMD_NUM |= EE_DTC_Cmd_R;
}
void ECU_EEPROM_UDS_WCMD(void)
{
//	G_u8_EE_CMD_NUM |= EE_UDS_Cmd_W;
}
void ECU_EEPROM_UDS_RCMD(void)
{
//	G_u8_EE_CMD_NUM |= EE_UDS_Cmd_R;
}



void ECU_EEPROM_RUN(void)
{
	u8 u8_Status = 0;
	u8 u8_Count = 0;
	if(G_u8_EE_RUN_FLG)
	{
		/*选择运行的指令码-对应的函数体*/
		switch(G_u8_EE_RUN_CMD)
		{
			case EE_IDEL:
			{
				G_u8_EE_RUN_FLG = 0;
				break;
			}
			case EE_OBD_Cmd_W:
			{
				u8_Status = ECU_EE_Run_WData();
				if(u8_Status)
				{
					G_u8_EE_RUN_CmdNum &= ~EE_OBD_Cmd_W;
					G_u8_EE_RUN_FLG = 0;
				}
				break;
			}
			case EE_OBD_Cmd_R:
			{
				u8_Status = ECU_EE_Run_RData();
				if(u8_Status)
				{
					G_u8_EE_RUN_CmdNum &= ~EE_OBD_Cmd_R;
					G_u8_EE_RUN_FLG = 0;
				}
				break;
			}
			case EE_DTC_Cmd_W:
			{
				u8_Status = ECU_EE_Run_WData();
				if(u8_Status)
				{
					G_u8_EE_RUN_CmdNum &= ~EE_DTC_Cmd_W;
					G_u8_EE_RUN_FLG = 0;
				}
				break;
			}
			case EE_DTC_Cmd_R:
			{
				u8_Status = ECU_EE_Run_RData();
				if(u8_Status)
				{
					G_u8_EE_RUN_CmdNum &= ~EE_DTC_Cmd_R;
					G_u8_EE_RUN_FLG = 0;
				}
				break;
			}
			/*******************************************************
			case EE_UDS_Cmd_W:
			{
				u8_Status = ECU_EEPROM_WUDS();
				if(u8_Status)
				{
					G_u8_EE_RUN_CmdNum &= ~EE_UDS_Cmd_W;
					G_u8_EE_RUN_FLG = 0;
				}
				break;
			}
			case EE_UDS_Cmd_R:
			{
				u8_Status = ECU_EEPROM_RUDS();
				if(u8_Status)
				{
					G_u8_EE_RUN_CmdNum &= ~EE_UDS_Cmd_R;
					G_u8_EE_RUN_FLG = 0;
				}
				break;
			}
			*******************************************************/
			default:
			{
				G_u8_EE_RUN_CmdNum = 0;
				G_u8_EE_RUN_CMD = EE_IDEL;
				break;
			}
		}
	}
	else
	{
		if(G_u8_EE_RUN_CmdNum != 0)				/*解析当前运行的功能指令码--获得实际的运行指令和置位运行标志*/
		{
			for(u8_Count = 0;u8_Count < 8;u8_Count ++)
			{
				if(G_u8_EE_RUN_CmdNum & (1 << u8_Count))
				{
					G_u8_EE_RUN_CMD = (1 << u8_Count);
					G_u8_EE_RUN_FLG = 1;
					break;	/*取出指令 跳出指令获取*/
				}
			}
		}
		else
		{
			if(G_u8_EE_CMD_NUM != 0)
			{
				G_u8_EE_RUN_CmdNum = G_u8_EE_CMD_NUM;
				G_u8_EE_CMD_NUM = 0;
			}
			else
			{
				BSW_GPIO_SetBits(PTE,0);
			}
			G_u8_EE_RUN_CMD = 0;
		}
	}
}




/********************************************************
**函数名：	ECU_EEPROM_IDEL_Check
**功能：		读取当前EE操作是否为空闲状态
**输入参数：	无
**返回值：	EE当前状态 true为空闲  false为非空闲
**注意：		操作EE时必须调用次函数才可进行操作
*********************************************************/
u8 ECU_EEPROM_IDEL_Check(void)
{
	u8 u8_Status = false;
	if(G_u8_EE_RUN_CmdNum == 0)
	{
		u8_Status = true;
	}
	return u8_Status;
}


























































/***********************************

ECU_EE_UN G_un_Data1,G_un_Data2;

void ECU_EEPROM_WEtrt(u32 u32_Data1,u32 u32_Data2)
{
	u16 G_u16_CrcData = 0;
	EE_TxStr.P_Tx_DataArr[0] = ((u32_Data1 >> 24) & 0xFF);
	EE_TxStr.P_Tx_DataArr[1] = ((u32_Data1 >> 16) & 0xFF);
	EE_TxStr.P_Tx_DataArr[2] = ((u32_Data1 >> 8) & 0xFF);
	EE_TxStr.P_Tx_DataArr[3] = (u32_Data1 & 0xFF);
	EE_TxStr.P_Tx_DataArr[4] = ((u32_Data2 >> 24) & 0xFF);
	EE_TxStr.P_Tx_DataArr[5] = ((u32_Data2 >> 16) & 0xFF);
	EE_TxStr.P_Tx_DataArr[6] = ((u32_Data2 >> 8) & 0xFF);
	EE_TxStr.P_Tx_DataArr[7] = (u32_Data2 & 0xFF);
	G_u16_CrcData = ECU_CRC_EEPROM(EE_TxStr.P_Tx_DataArr,8);
	EE_TxStr.P_Tx_DataArr[8] = ((G_u16_CrcData >> 8) & 0xFF);
	EE_TxStr.P_Tx_DataArr[9] = (G_u16_CrcData & 0xFF);
	EE_TxStr.P_Tx_DataArr[10] = IIC_Stop(0x00);
}

void ECU_EEPROM_WArry(u8* P_u8_Data_Arr)
{
	u16 u16_CrcData = 0;

	EE_TxStr.P_Tx_DataArr[0] = P_u8_Data_Arr[0];
	EE_TxStr.P_Tx_DataArr[1] = P_u8_Data_Arr[1];
	EE_TxStr.P_Tx_DataArr[2] = P_u8_Data_Arr[2];
	EE_TxStr.P_Tx_DataArr[3] = P_u8_Data_Arr[3];
	EE_TxStr.P_Tx_DataArr[4] = P_u8_Data_Arr[4];
	EE_TxStr.P_Tx_DataArr[5] = P_u8_Data_Arr[5];
	EE_TxStr.P_Tx_DataArr[6] = P_u8_Data_Arr[6];
	EE_TxStr.P_Tx_DataArr[7] = P_u8_Data_Arr[7];
	u16_CrcData = ECU_CRC_EEPROM(EE_TxStr.P_Tx_DataArr,8);
	EE_TxStr.P_Tx_DataArr[8] = ((u16_CrcData >> 8) & 0xFF);
	EE_TxStr.P_Tx_DataArr[9] = (u16_CrcData & 0xFF);
	EE_TxStr.P_Tx_DataArr[10] = IIC_Stop(0x00);
}



u8 ECU_EE_Delay(u8 *Sub_P(void))
{
	u8 u8_Status = 0;
	static u8 S_u8_Cnt = 0;
	if(S_u8_Cnt>5)
	{
		u8_Status = (*Sub_P)();
		S_u8_Cnt = 0;
	}
	else
	{
		S_u8_Cnt++;
	}
	return u8_Status;
}

void ECU_ValType_Change(u32 u32_Data_Addr,u8* P_u8_Data,u8 u8_Lenth,u8 B_Data_u8_Flg)
{
	u8 u8_Count = 0;
	u8* P_u8_DataMid;
	P_u8_DataMid = (u8*)(u32_Data_Addr);
	for(u8_Count=0;u8_Count<u8_Lenth;u8_Count++)
	{
		if(B_Data_u8_Flg)
		{
			P_u8_Data[u8_Count] = P_u8_DataMid[u8_Count];
		}
		else
		{
			P_u8_DataMid[u8_Count] = P_u8_Data[u8_Count];
		}
	}
}


********************************/





